﻿using System;
using System.Collections.Generic;
using System.Text;

namespace TrackingAssist.WebTrends
{
    public class SectionFilter:IFilter
    {
        public IList<string> GetDataSource()
        {
            if (WebTrendsView.WebTrendsSpecList != null && WebTrendsView.WebTrendsSpecList.Count > 0)
            {
                IList<string> sectionList = new List<string>();

                foreach (WebTrends webtrends in WebTrendsView.WebTrendsSpecList)
                {
                    if (webtrends.Section != null && !webtrends.Section.Value.StartsWith("[") && !webtrends.Section.Value.Equals(string.Empty) && !sectionList.Contains(webtrends.Section.Value))
                    {
                        sectionList.Add(webtrends.Section.Value);
                    }
                }

                return sectionList;
            }
            return null;
        }


        public IList<WebTrends> GetFiltedSpecItems(IList<string> selectedItem)
        {
            if (selectedItem!=null && selectedItem.Count > 0)
            {
                IList<WebTrends> specList = new List<WebTrends>();
                
                foreach (var item in selectedItem)
                {
                    foreach (WebTrends webtrends in WebTrendsView.WebTrendsSpecList)
                    {
                        if (string.Equals(webtrends.Section.Value, item))
                            specList.Add(webtrends);
                    }
                }

                return specList;
            }
            else
            {
                return null;
            }
        }
    }
}
